package com.example.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.srb.common.result.Result;
import com.example.srb.core.pojo.entity.Borrower;
import com.example.srb.core.pojo.vo.BorrowerApprovalVO;
import com.example.srb.core.pojo.vo.BorrowerDetailVO;
import com.example.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-02-20
 */
@RestController
@RequestMapping("/admin/core/borrower")
@Api(tags = "借款人管理")
@Slf4j
public class AdminBorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("获取借款人分页列表")
    @GetMapping("/listPage/{pageNum}/{pageSize}")
    public Result listPage(@ApiParam(value = "当前页码",required = true)@PathVariable Long pageNum,
                           @ApiParam(value = "每页记录数",required = true)@PathVariable Long pageSize,
                           @ApiParam(value = "搜索关键词",required = false)@RequestParam String keyword){

        Page<Borrower> pageParam = new Page<>(pageNum,pageSize);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);
        return Result.ok().data("pageModel",pageModel);
    }

    @ApiOperation("获取借款人详细信息")
    @GetMapping("/show/{id}")
    public Result show(@ApiParam(value = "借款人id",required = true)@PathVariable Long id){

        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
        return Result.ok().data("borrowerDetailVO",borrowerDetailVO);
    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return Result.ok().message("审批完成!");
    }

}

